package net.thermetics.fx.features;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Details an individual Feature: its metadata and so forth. A
 * Feature is a collection of Feature Components, plus metadata.
 * Each component is basically a userscript or iframe-based widget
 * hosted on appspot. Components have access to jQuery and the TFX
 * JavaScript API.
 * @author projectmoon
 *
 */
public class Feature {
	private String name;
	private String id;
	private Set<Component> components = new HashSet<Component>();
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public Set<Component> getComponents() {
		return Collections.unmodifiableSet(components);		
	}
	
	public void addComponent(Component component) {
		components.add(component);
	}
	
	public boolean removeComponent(Component component) {
		return components.remove(component);
	}
	
	public void addAll(Collection<Component> components) {
		components.addAll(components);
	}
	
	/**
	 * Verifies this feature by calling verify on each of its
	 * child components.
	 */
	public void verify() {
		for (Component component : getComponents()) {
			component.verify();
		}
	}
}
